#ifndef __H_GAME_H__
#define __H_GAME_H__

#include <deque>
#include <vector>
#include <map>
#include "ICC_Timer_Handler.h"
#include "RedisClient.h"
#include "GameBase.h"
#include "DbPart.h"
#include "CClient.h"
#include "def.h"
#include "HostBase.h"

using namespace std;

class CHost;
class CGameServer :public BYTimerOject
{
public:
	CGameServer();
	virtual ~CGameServer();
public:
	// callback && interface
	virtual bool InitGame();
	virtual int OnBYTimeOut(int Timerid);
	int ProcessPacket(SocketHandler* pHandler, NETInputPacket* inputPkg);
	int ProcEventClientClose(int ev_id, SpiderEvent* pEvent);
	int ProcEventGameInit(int ev_id, SpiderEvent* pEvent);
private:
    int onOnline(SocketHandler* pHandler, NETInputPacket* inputPkg);
	int onOffline(SocketHandler* pHandler, NETInputPacket* inputPkg);
	int onStateQuery(SocketHandler* pHandler, NETInputPacket* inputPkg);
	int onOnlineGameStateQuery(SocketHandler* pHandler, NETInputPacket* inputPkg);
	int onOnlineSyn(SocketHandler* pHandler, NETInputPacket* inputPkg);
	int onGameIn(SocketHandler* pHandler, NETInputPacket* inputPkg);
	int onGameOut(SocketHandler* pHandler, NETInputPacket* inputPkg);
	int onInGameSyn(SocketHandler* pHandler, NETInputPacket* inputPkg);
	int onOnlineUserListReq(SocketHandler* pHandler, NETInputPacket* inputPkg);
	int onOnlineAllUserListReq(SocketHandler* pHandler, NETInputPacket* inputPkg);
	void procAgentClose(const unsigned int agentid);
	void procGameClose(const unsigned short srvtype, const unsigned int srvid);
	void kick(unsigned int uid, unsigned int agentId);
	//void synOnlineNum(const unsigned int uid = 0);
	void offlineCache(const unsigned int uid);
	void rmOfflineCache(const unsigned int uid);
	int procOfflineCacheCheck(void);
	void offlineNotify(const unsigned int uid, const unsigned int agentid, const unsigned short srvtype, const unsigned int srvid);
	void onlineNotify(const unsigned int uid, const unsigned int agentid, const unsigned short srvtype, const unsigned int srvid);
	map<unsigned int, stPlayer> m_player;
	map<unsigned int, _u64_> m_offlineCache;
	unsigned int m_onlineCount;
public:
	CHost* m_pHost;
	//CDbPart m_dbHandler;
};


#endif


